package com.naiyumi.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.naiyumi.common.DB;
import com.naiyumi.common.DBConnect;
import com.naiyumi.dao.DownloadDao;

@Repository
public class DownloadDaoImpl implements DownloadDao{
	
	@Autowired
	protected DB dbUtil;
	@Autowired
	private DBConnect dbConnect;
	@Override
	public int getPasswordByFloder(String floder, String password) {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(1) from g_floder where floder_name = '"+floder+"' and floder_password = '"+password+"'");
		return this.dbConnect.execQueryForInt(sql.toString());
	}
	@Override
	public int setPasswordByFloder(String floder, String password) {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(1) from g_floder where floder_name = '"+floder+"'");
		int count = this.dbConnect.execQueryForInt(sql.toString());
		if(count > 0){
			sql = new StringBuffer();
			sql.append("update g_floder set floder_password = '"+password+"' where floder_name = '"+floder+"'");
		} else {
			sql = new StringBuffer();
			sql.append("insert into g_floder (floder_name,floder_password) VALUES ('"+floder+"','"+password+"')");
		}
		return this.dbConnect.execUpdate(sql.toString());
	}
	
}
